package semantic.analyzer;

import metamodel.PrimitiveTypeEnum;
import semantic.SemanticException;
import semantic.model.ExpressionNode;
import semantic.model.UndefinedExpressionNode;

public class UnaryExpressionAnalyzer {

	public static void checkConcordance(ExpressionNode node1, ExpressionNode node2) {
		if (node2.getType().equalsIgnoreCase(PrimitiveTypeEnum.UNDEFINED.name())) {
			UndefinedExpressionNode node = (UndefinedExpressionNode) node2;
			node.setTypeItShouldBe(node1.getType());
		} else {
			boolean condition1 = node2.getType().equalsIgnoreCase(PrimitiveTypeEnum.REAL.name()) && node1.getType().equalsIgnoreCase(PrimitiveTypeEnum.REAL.name());
			boolean condition2 = node1.getType().equalsIgnoreCase(PrimitiveTypeEnum.BOOLEAN.name()) && node2.getType().equalsIgnoreCase(PrimitiveTypeEnum.BOOLEAN.name());
			if (!condition1 && !condition2) {
				throw new SemanticException("Incoformidade de tipos: " + node1.getType() + " != " + node2.getType());
			}
		}
	}

}
